home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / asm / sterm / sterm.s
Encoding:
Text File  |  1993-09-13  |  31.0 KB  |  1,214 lines

  1. *------------------------------------------------------------------------*
  2. * STerminal - a communications program.                                  *
  3. * FreeWare from Antic - the Atari Resource                               *
  4. * (c) 1985 Antic Publishing / Jeremy E. San                              *
  5. * Version 101785                                                         *
  6. * Written by Jeremy E. San                                               *
  7. * Re-Edited by Patrick Bass    Antic ST program editor                   *
  8. *------------------------------------------------------------------------*
  9.  
  10. brate    equ    9        300 baud default baud rate
  11. xon    equ    $11        Ctrl Q
  12. xoff    equ    $13        Ctrl S
  13. esc    equ    27        Escape character in vt52 mode
  14. cr    equ    13        Carriage Return
  15. lf    equ    10        Line Feed
  16.  
  17. * Xmodem definitions...
  18. soh    equ    $01
  19. eot    equ    $04
  20. ack    equ    $06
  21. nak    equ    $15
  22. can    equ    $18
  23.  
  24. *-------------------------------------------------------------------------*
  25. start    move.l    a7,a5            * save a7 so we can get the base page address
  26.     move.l    #ustk,a7    * set local stack
  27.     move.l    4(a5),a5    * basepage address
  28.     move.l    $c(a5),d0
  29.     add.l    $14(a5),d0
  30.     add.l    $1c(a5),d0
  31.     add.l    #$100,d0    * skip los pageos baseos
  32.     move.l    d0,-(sp)
  33.     move.l    a5,-(sp)
  34.     move    d0,-(sp)    * junk word
  35.     move    #$4a,-(sp)
  36.     trap    #1
  37.     add.l    #12,sp
  38. *
  39. * Now, here comes MY bit of the program, the terminal.
  40. *
  41.  
  42. *-------------------------------------------------------------------------*
  43. _main    
  44.     lea.l    start(pc),a5    Master index to make program position
  45. startup    
  46.     bsr    init        Anything worth initialising these days?
  47.  
  48.     lea.l    welcome(a5),a0    Howdy doody pard`ner
  49.     bsr    message        Print message
  50.  
  51. mainloop
  52.     bsr    scankey        Try scanning for a key
  53.     tst.l    d0        Got one?
  54.     beq.s    notkeyu        Nope!
  55.  
  56.     swap    d0        test for help key?
  57.     cmp.b    #$62,d0        Yes?
  58.     beq    trymenu        Was it the menu command?
  59.  
  60.     swap    d0
  61.     move.w    d0,d1        Transfer into d1 for output
  62.     bsr    sendser        Yes, so send it
  63. notkeyu    
  64.     move.b    fileflag(a5),d0    Are we uploading?
  65.     cmp.b    #"U",d0        Yes??
  66.     bne.s    notkey1        Nope!
  67.  
  68.     move.l    ubufptr(a5),a0    Get upload pointer
  69.     move.l    bufptr(a5),a1    Get normal pointer
  70.     cmp.l    a1,a0        Have we finished yet?
  71.     bge.s    finupl        Yup!
  72.  
  73.     clr.w    d1        Clear reggie
  74.     move.b    (a0)+,d1    Get a byte
  75.     move.l    a0,ubufptr(a5)    Update pointer
  76.     bsr    sendser        Send it
  77.     bra.s    notkey1        .. and continue!
  78. finupl    
  79.     clr.b    fileflag(a5)    Signal end of upload
  80. notkey1    
  81.     bsr    scanser        Try scanning the serial port?
  82.     tst.l    d0        Got a character?
  83.     bmi.s    mainloop    nope!
  84.  
  85.     and.w    #$7f,d0        Mask out parity bit
  86.     move.w    d0,d1        Transfer to d1
  87.     bsr    wrchar        Print it on screen
  88.  
  89.     move.b    fileflag(a5),d0    Are we downloading?
  90.     cmp.b    #"D",d0        If not,
  91.     bne.s    mainloop        simply continue
  92.  
  93.     move.l    bufptr(a5),a0    We ARE downloading,
  94.     move.b    d1,(a0)+        ..so put next character
  95.     move.l    a0,bufptr(a5)    ..into the buffer
  96.     lea.l    buffer(a5),a1    Buffer overflow?
  97.     sub.l    a1,a0        Subtract start buffer frm current buff pos
  98.     cmp.l    #$ffff,a0    Too big(ish)?
  99.     bge    savebuf        Yup, so force the user to save it!
  100.  
  101.     bra.s    mainloop        One Mo Time!
  102.  
  103. *-------------------------------------------------------------------------*
  104. * Enter the menu mode from HELP being pressed
  105. trymenu    
  106.     move.w    #xoff,d1    Send XOFF character to stop host waffling
  107. *    bsr    sendser        Temporarily disabled to prevent freezing.
  108.  
  109. * Menu mode selected, so go display it :
  110. menuagn    
  111.     lea.l    themenu(a5),a0    Display menu message
  112.     bsr    message        etc
  113.  
  114.     bsr    rdchar        get a key
  115.     cmp.b    #esc,d0        Escape?
  116.     beq    menuexit        .. exits
  117.  
  118.     and.w    #$df,d0        mask out lower case
  119.     cmp.b    #"H",d0        Help required?
  120.     beq    menuhelp        go for it
  121.  
  122.     cmp.b    #"E",d0        E for Exit?
  123.     beq    menuexit
  124.  
  125.     cmp.b    #"Q",d0        Q for Quit?
  126.     beq    exitprog
  127.  
  128.     cmp.b    #"B",d0        B for Baud rate?
  129.     beq    alterbd
  130.  
  131.     cmp.b    #"C",d0        C for clear buffer?
  132.     beq    bufclr
  133.  
  134.     cmp.b    #"D",d0        D for download?
  135.     beq    dodownl
  136.  
  137.     cmp.b    #"S",d0        S for save buffer?
  138.     beq    savebuf
  139.  
  140.     cmp.b    #"L",d0        L for Load to buffer?
  141.     beq    loadbuf
  142.  
  143.     cmp.b    #"I",d0        I for buffer Info?
  144.     beq    showinf
  145.  
  146.     cmp.b    #"U",d0        U for Upload?
  147.     beq    uplode
  148.  
  149.     cmp.b    #"X",d0        X for xmodem?
  150.     beq    xmodem
  151.  
  152.     cmp.b    #"F",d0        F for Freeware?
  153.     beq    freeware
  154.  
  155.     bra    menuagn        Print the menu again
  156.  
  157. *-------------------------------------------------------------------------*
  158. menuhelp
  159.     lea.l    helpmes(a5),a0    point to Help message
  160.     bsr    message        .. and print it
  161.     bra    menuagn        .. and back to menu again
  162. menuexit
  163.     move.w    #xon,d1        Ctrl Q to let host resume sending
  164.     bsr    sendser        do it
  165.  
  166.     lea.l    exitmes(a5),a0    tell user we are
  167.     bsr    message        ... exiting the menu
  168.     bra    mainloop        .. and exit!
  169.  
  170.  
  171. exitmes    
  172.     dc.b    cr,lf,lf,"Terminal Mode.",cr,lf,lf,0
  173.     even
  174.  
  175. themenu    
  176.     dc.b    cr,lf,lf," STerminal Extended Menu.",cr,lf
  177.     dc.b    " Press ",34,"H",34," for more extensive help,",cr,lf
  178.     dc.b    " Or: B,C,D,E,F,I,L,Q,S,U,X ?",cr,lf,0
  179.     even
  180.  
  181. helpmes    
  182.     dc.b    cr,lf,lf
  183.     dc.b    " HELP, - Press a single letter as follows :",cr,lf,lf
  184.     dc.b    " B = Set the baud rate,",cr,lf
  185.     dc.b    " C = Clear the Capture Buffer,",cr,lf
  186.     dc.b    " D = Download text into Capture Buffer,",cr,lf
  187.     dc.b    " E = Exit from here back to terminal mode,",cr,lf
  188.     dc.b    " F = Freeware information notice,",cr,lf
  189.     dc.b    " I = Information about the Buffer,",cr,lf
  190.     dc.b    " L = Load a file into Capture Buffer,",cr,lf
  191.     dc.b    " Q = Quit STerminal,",cr,lf
  192.     dc.b    " S = Save Capture Buffer to a file,",cr,lf
  193.     dc.b    " U = Upload text from Capture Buffer,",cr,lf
  194.     dc.b    " X = Xmodem file transfer (MODEM7).",cr,lf,0
  195.     even
  196.  
  197. *-------------------------------------------------------------------------*
  198. alterbd    
  199.     lea.l    baudmes(a5),a0    Show user the baudrates available
  200.     bsr    message
  201.  
  202.     bsr    rdchar        Get a choice
  203.     cmp.b    #cr,d0        Return..?
  204.     beq    exitbd
  205.  
  206.     cmp.b    #esc,d0        Escape..?
  207.     beq    exitbd        If either, then exit!
  208.     and.w    #$df,d0        Mask out Lower Case
  209.  
  210.     sub.w    #65,d0        Convert to numeric from ascii
  211.     cmp.w    #15,d0        Too big?
  212.     bgt    alterbd        Repeat it for the hard of hearing!
  213.  
  214.     bsr    setbaud        Set the baud rate!
  215. exitbd    
  216.     bra    menuagn        Zap back to menu
  217.  
  218. *-------------------------------------------------------------------------*
  219. baudmes    
  220.     dc.b    cr,lf,lf," Please select one of the following, or",cr,lf
  221.     dc.b    " press RETURN to return to menu :",cr,lf,lf
  222.     dc.b    " A) 19,200",cr,lf
  223.     dc.b    " B)  9,600",cr,lf
  224.     dc.b    " C)  4,800",cr,lf
  225.     dc.b    " D)  3,600",cr,lf
  226.     dc.b    " E)  2,400",cr,lf
  227.     dc.b    " F)  2,000",cr,lf
  228.     dc.b    " G)  1,800",cr,lf
  229.     dc.b    " H)  1,200",cr,lf
  230.     dc.b    " I)    600",cr,lf
  231.     dc.b    " J)    300",cr,lf    <<--== Default!
  232.     dc.b    " K)    200",cr,lf
  233.     dc.b    " L)    150",cr,lf
  234.     dc.b    " M)    134",cr,lf
  235.     dc.b    " N)    110",cr,lf
  236.     dc.b    " O)     75",cr,lf
  237.     dc.b    " P)     50",cr,lf
  238.     dc.b    lf," Your Choice ?",cr,lf,0
  239.     even
  240.  
  241. cbufmes    
  242.     dc.b    cr,lf,lf," Capture Buffer cleared.",cr,lf,lf,0
  243.     even
  244.  
  245. *-------------------------------------------------------------------------*
  246. * Clear the capture buffer
  247. bufclr    
  248.     lea.l    cbufmes(a5),a0    Point to message
  249.     bsr    message        And print it
  250.  
  251.     lea.l    buffer(a5),a0    Point to start of buffer
  252.     move.l    a0,bufptr(a5)    Adjust buffer pointer
  253.     bsr    infobuf        Show info about buffer
  254.     bra    menuagn        Back to menu
  255.  
  256. *-------------------------------------------------------------------------*
  257. * Start a download...
  258. dodownl    
  259.     move.b    fileflag(a5),d0    Are we already downloading?
  260.     cmp.b    #"D",d0        if so, 
  261.     beq.s    down2        Then branch to DOWNLOAD OFF
  262.  
  263. * Turn downloading ON
  264.     lea.l    dwnmes1(a5),a0    Point to ON message
  265.     bsr    message        print it
  266.     move.b    #"D",fileflag(a5)    signal download ON
  267.     bsr    infobuf        Show capture buffer length
  268.     bra    menuagn        Back to menu
  269.  
  270. * Turn downloading OFF
  271. down2    
  272.     lea.l    dwnmes2(a5),a0    Point to OFF message
  273.     bsr    message        Print it
  274.     clr.b    fileflag(a5)    Set download flag to OFF
  275.     bsr    infobuf        Show length of capture buffer
  276.     bra    menuagn        Back to menu
  277.  
  278.  
  279. dwnmes1    
  280.     dc.b    cr,lf,lf,"Downloading incoming text Now.",cr,lf,lf,0
  281.     even
  282. dwnmes2    
  283.     dc.b    cr,lf,lf,"Okay, I`m not downloading anymore!",cr,lf,lf,0
  284.     even
  285.  
  286. *-------------------------------------------------------------------------*
  287. * Start an upload
  288. uplode    
  289.     move.b    fileflag(a5),d0        Are we uploading already?
  290.     cmp.b    #"U",d0            yes?
  291.     beq    alredu
  292.  
  293.     move.l    bufptr(a5),a0        If nothing in buffer,
  294.     lea.l    buffer(a5),a1        .. then forget it,
  295.     cmp.l    a0,a1            .. Bub!
  296.     beq    exitu1
  297.  
  298.     move.b    #"U",fileflag(a5)    Say its an upload!
  299.     lea.l    buffer(a5),a0        Point to start of buffer
  300.     move.l    a0,ubufptr(a5)        Save it!
  301.  
  302.     lea.l    uplmes1(a5),a0        Uploading message
  303.     bsr    message
  304. exitu1    
  305.     bra    menuagn
  306.  
  307. alredu    
  308.     clr.b    fileflag(a5)        Cancel Upload!
  309.     lea.l    uplmes2(a5),a0        Cancelled message
  310.     bsr    message
  311.     bra    menuagn
  312.  
  313. *-------------------------------------------------------------------------*
  314. uplmes1    
  315.     dc.b    cr,lf,lf,"Upload will commence when you exit.",cr,lf,lf,0
  316.     even
  317.  
  318. uplmes2    
  319.     dc.b    cr,lf,lf,"Upload has been cancelled, Snif.",cr,lf,lf,0
  320.     even
  321.  
  322. *-------------------------------------------------------------------------*
  323. showinf    
  324.     bsr    infobuf        Shop the info,
  325.     bra    menuagn        .. then return
  326.  
  327. *-------------------------------------------------------------------------*
  328. * Display how many characters in buffer...
  329. infobuf    
  330.     bsr    newline        Start of a new ilne
  331.     move.w    #36,d1        Print a hex $ sign
  332.     bsr    wrchar
  333.  
  334.     move.l    bufptr(a5),a0    Current buffer pointer...
  335.     lea.l    buffer(a5),a1    start of buffer
  336.     sub.l    a1,a0        Subtract one from tuther,
  337.     move.w    a0,d1        = length of buffer!
  338.     bsr    hexword        And print it
  339.  
  340.     lea.l    infmes1(a5),a0    .. followed by nice friendly text
  341.     bra    message        print
  342.  
  343. infmes1    
  344.     dc.b    " characters in Capture Buffer.",cr,lf,0
  345.     even
  346.  
  347. *-------------------------------------------------------------------------*
  348. * Save file from buffer
  349. savebuf    
  350.     lea.l    savmes1(a5),a0    Tell `em were saving the file
  351.     bsr    message        and print it
  352.  
  353.     lea.l    buffer(a5),a0    If buffer is empty...
  354.     move.l    bufptr(a5),a1    .. then dont bother...
  355.     cmp.l    a0,a1        .. saving it!
  356.     beq    skipsav
  357.  
  358.     bsr    infobuf        Show length of buffer
  359.     bsr    askfile        Get a filename
  360.     tst.w    d0        nothing typed?
  361.     beq.s    skipsav        Ignore file save then!
  362.  
  363.     bsr    savefile        Save actual file
  364.     lea.l    sbufmes(a5),a0    Buffer saved message
  365.     bsr    message        Print it
  366. skipsav    
  367.     bra    menuagn        Back to menu
  368.  
  369. *-------------------------------------------------------------------------*
  370. * Load file to buffer
  371. loadbuf    
  372.     lea.l    lodmes1(a5),a0    Tell em about it, honeybun
  373.     bsr    message
  374.  
  375.     bsr    infobuf        Show length of buffer
  376.     bsr    askfile        Get a filename
  377.     tst.w    d0        Nothing typed?
  378.     beq    skiplod
  379.  
  380.     bsr    loadfile        Load it pronto!
  381.     bsr    infobuf        Show new size of buffer
  382. skiplod    
  383.     bra    menuagn
  384.  
  385.  
  386. savmes1    
  387.     dc.b    cr,lf,lf,"Save the Buffer to a diskfile.",cr,lf,0
  388.     even
  389.  
  390. lodmes1    
  391.     dc.b    cr,lf,lf,"Load a diskfile into the Buffer.",cr,lf,0
  392.     even
  393.  
  394. filemes    
  395.     dc.b    cr,lf,lf,"Filename ?",0
  396.     even
  397.  
  398. *-------------------------------------------------------------------------*
  399. freeware
  400.     lea.l    freemes(a5),a0
  401.     bsr    message
  402.  
  403.     bsr    rdchar
  404.     bra    menuagn
  405.  
  406. freemes    
  407.     dc.b    cr,lf
  408.   dc.b    "   A limited license is granted to all users of this program to make copies",cr,lf
  409.   dc.b    " of STerminal and distribute them to other users on the following conditions...",cr,lf
  410.   dc.b    " 1.) All Freeware and copyright notices contained in the",cr,lf
  411.   dc.b    "     program are not to be altered or removed.  Anyone doing so may",cr,lf
  412.   dc.b    "     be regarded as a contributory copyright violator.",cr,lf
  413.   dc.b    " 2.) The program is not to be distributed to others in",cr,lf
  414.   dc.b    "     modified form.",cr,lf
  415.   dc.b    " 3.) No fee is to be charged for copying or distributing the",cr,lf
  416.   dc.b    "     program without an express written agreement with Antic",cr,lf
  417.   dc.b    "     Publishing, Inc.",cr,lf
  418.   dc.b    " STerminal is the copyrighted work of Jeremy E. San and is not in the public",cr,lf
  419.   dc.b    " domain.  The author grants permission to users of this program to",cr,lf
  420.   dc.b    " make as many copies of the program as they wish and to give these",cr,lf
  421.   dc.b    " copies to others.  STerminal may also be uploaded to and downloaded from",cr,lf
  422.   dc.b    " free, public BBS' and commercial systems such as Compuserve by subscribers",cr,lf
  423.   dc.b    " so long as the only charge paid by the subscriber is for on-line time and",cr,lf
  424.   dc.b    " there is no charge for the program.  If you have recieved a copy of STerminal",cr,lf
  425.   dc.b    " free, from a source other than Antic, and you find that this program",cr,lf
  426.   dc.b    " is useful, you are invited to make a donation of $6.00 to the author.",cr,lf
  427.   dc.b    "  The donation is voluntary and should not be considered payment for software",cr,lf
  428.   dc.b    " or services.  The author is:",cr,lf
  429.   dc.b    "             Jeremy E. San",cr,lf
  430.   dc.b    "             129,  The Broadway",cr,lf
  431.   dc.b    "             Mill Hill,  London",cr,lf
  432.   dc.b    "             NW7  4RN,  England",0
  433.     even
  434.  
  435. *-------------------------------------------------------------------------*
  436. * Flush the serial input buffer, in 1 easy lesson
  437. flushser
  438.     bsr    scanser
  439.     bpl.s    flushser
  440.     rts
  441.  
  442. *-------------------------------------------------------------------------*
  443. * Xmodem file transfer bits...
  444. xmodem    
  445.     lea.l    xmes1(a5),a0
  446.     bsr    message
  447.  
  448.     bsr    rdchar
  449.     and.w    #$df,d0
  450.  
  451.     cmp.b    #"U",d0
  452.     beq    xmodemup
  453.     cmp.b    #"D",d0
  454.     beq    xmodemdn
  455.     bra    menuagn
  456.  
  457. xmes1    
  458.     dc.b    cr,lf,lf,"Xmodem transfer, <U>pload or <D>ownload ?",cr,lf,0
  459.     even
  460.  
  461. upmes1    
  462.     dc.b    cr,lf,"Waiting for receiver...",cr,lf,0
  463.     even
  464.  
  465. uperr1    
  466.     dc.b    cr,lf,"Receiver not happy, retrying...",cr,lf,0
  467.     even
  468.  
  469. updun1    
  470.     dc.b    cr,lf,"File transferred safely.",cr,lf,0
  471.     even
  472.  
  473.  
  474. *-------------------------------------------------------------------------*
  475. * Send file using Xmodem...
  476. xmodemup
  477.     bsr    warnmess
  478.     lea.l    buffer(a5),a4        start of buffer
  479.     moveq    #1,d2            block number in d2, default=1
  480.  
  481. * Start by waiting for an initial NAK from the receive side.
  482. xmodeup0
  483.     lea.l    upmes1(a5),a0
  484.     bsr    message
  485.  
  486.     move.w    #12,d6            timeout
  487.     bsr    waitser            wait for a char for a bit?
  488.     bmi.s    xsendblk
  489.  
  490.     cmp.b    #nak,d0            any luck?
  491.     bne.s    xmodeup0
  492.  
  493. * Check for End of File here...
  494. xsendblk
  495.     bsr    scankey            does user want to cancel?
  496.     bne    xcancel            yup
  497.  
  498.     move.l    bufptr(a5),a0        are we at end of buffer!?
  499.     cmpa.l    a4,a0
  500.     ble    finxup            show an end of file, if we are
  501.  
  502. * Send a block, Xmodem fashion...
  503.     bsr    prblock
  504.     clr.b    d3            checksum
  505.     move.b    #soh,d1            start of block
  506.     bsr    sendser
  507.     move.b    d2,d1            block number
  508.     bsr    sendser
  509.     move.b    d2,d1
  510.     not.b    d1            invert it to be sure
  511.     bsr    sendser
  512.     move.w    #127,d4            counter for number of bytes
  513. xmodeulp
  514.     move.b    (a4)+,d1        get a byte
  515.     add.b    d1,d3            compute checksum
  516.     bsr    sendser            send it
  517.     dbra    d4,xmodeulp        and go back for more
  518.     move.b    d3,d1            send checksum
  519.     bsr    sendser
  520.  
  521. wait10s    
  522.     move.w    #10,d6            wait 10 secs...
  523.     bsr    waitser
  524.     bmi.s    upnogood
  525.  
  526.     cmp.b    #ack,d0            acknowledged.. whee...
  527.     beq.s    upgonext
  528.  
  529.     cmp.b    #can,d0            cancelled, hmmm!
  530.     beq.s    xcancel
  531.  
  532.     cmp.b    #nak,d0
  533.     bne.s    wait10s
  534.  
  535. upnogood
  536.     lea.l    uperr1(a5),a0
  537.     bsr    message
  538. uretry    
  539.     sub.l    #128,a4            subtract a block number and retry
  540.     bra.s    xsendblk
  541.  
  542. upgonext
  543.     addq.b    #1,d2
  544.     bra.s    xsendblk
  545.  
  546. finxup    
  547.     move.b    #eot,d1            send end of file control
  548.     bsr    sendser
  549.  
  550. finxup1    
  551.     move.w    #10,d6
  552.     bsr    waitser
  553.     bmi.s    finxup
  554.  
  555.     cmp.b    #ack,d0            did they accept?
  556.     beq.s    finxup2
  557.  
  558.     bra.s    finxup1
  559.  
  560. finxup2    
  561.     lea.l    updun1(a5),a0
  562.     bsr    message
  563.     bra    menuagn
  564.  
  565. *-------------------------------------------------------------------------*
  566. xcancel    
  567.     lea.l    cancmes(a5),a0
  568.     bsr    message
  569.     bsr    rdchar
  570.     bsr    newline
  571.     and.w    #$df,d0
  572.     cmp.b    #"Y",d0
  573.     beq    uretry
  574.  
  575.     move.b    #can,d1
  576.     bsr    sendser
  577.     bra    menuagn
  578.  
  579. *-------------------------------------------------------------------------*
  580. xrcancel
  581.     lea.l    cancmes(a5),a0
  582.     bsr    message
  583.     bsr    rdchar
  584.     bsr    newline
  585.     and.w    #$df,d0
  586.     cmp.b    #"Y",d0
  587.     beq    xreclp0        with Nak
  588.  
  589.     move.b    #can,d1
  590.     bsr    sendser
  591.     bra    menuagn
  592.  
  593. cancmes    
  594.     dc.b    cr,lf,"For some reason, the transfer has been Cancelled."
  595.     dc.b    cr,lf,"Bearing in mind that this could have been line"
  596.     dc.b    cr,lf,"noise, you may press Y to continue, or any other"
  597.     dc.b    cr,lf,"key to abort this transfer.",cr,lf,lf,0
  598.     even
  599.  
  600. rstart1    
  601.     dc.b    cr,lf,lf,"Initiating the transfer (NAK sent).",cr,lf,0
  602.     even
  603.  
  604. ret1mes    
  605.     dc.b    cr,lf,"No response, re-requesting block.",cr,lf,0
  606.     even
  607.  
  608. *-------------------------------------------------------------------------*
  609. xmodemdn
  610.     bsr    warnmess
  611.     lea.l    buffer(a5),a4
  612.  
  613.     moveq    #1,d2            block number default
  614.     lea.l    rstart1(a5),a0
  615.     bsr    message
  616.  
  617. * Send initial NAK
  618. xreclp0    
  619.     move.b    #nak,d1            send a NAK
  620.     bsr    sendser
  621.  
  622. xreclp1a
  623.     bsr    scankey
  624.     bne    xrcancel
  625.  
  626.     move.w    #12,d6            wait for block...
  627.     bsr    waitser
  628.     bpl.s    xrecok1            keep doing it, if nothing going
  629.  
  630.     lea.l    ret1mes(a5),a0        print up retry message
  631.     bsr    message
  632.     bra.s    xreclp0
  633.  
  634. xrecok1    
  635.     cmp.b    #soh,d0            start of block coming in?
  636.     beq.s    xrecrcv
  637.  
  638.     cmp.b    #eot,d0            end of file?
  639.     beq    xreceot
  640.  
  641.     cmp.b    #can,d0
  642.     beq    xrcancel
  643.  
  644.     bra.s    xreclp1a
  645.  
  646. * Block coming in...
  647. xrecrcv    
  648.     bsr    prblock
  649.     move.w    #6,d6        get block number
  650.     bsr    waitser
  651.     bmi    xrslowr
  652.  
  653.     cmp.b    d0,d2        same?
  654.     bne    xrbadblk    was a bad, or previously-repeated block
  655.  
  656.     move.w    #6,d6        get inverse block number
  657.     bsr    waitser
  658.     bmi    xrslowr
  659.  
  660.     not.b    d0
  661.     cmp.b    d0,d2        okay?
  662.     bne    xrbadbl2    definitely a bad block, not a repeat
  663.  
  664. * Get the 128 data bytes
  665.     move.w    #127,d4        byte count
  666.     clr.b    d3        checksum
  667. xrecrclp
  668.     move.w    #6,d6        timeout for each character
  669.     bsr    waitser
  670.     bmi.s    xrecnop3    missed a character, perhaps!?
  671.  
  672.     move.b    d0,(a4)+    store it
  673.     add.b    d0,d3        compute checksum
  674.     dbra    d4,xrecrclp    loop back for more
  675.  
  676.     move.w    #6,d6
  677.     bsr    waitser        get checksum
  678.     bmi.s    xrcheckm    not good?
  679.  
  680.     cmp.b    d0,d3        checksum any good?
  681.     bne.s    xrchecks
  682.  
  683. * Block was okay, so increment block number and go on...
  684.     addq.b    #1,d2
  685.     bsr    sendack
  686.     bra    xreclp1a
  687.  
  688. * A character was missed from inside a block
  689. xrecnop3
  690.     lea.l    misschm(a5),a0
  691.     bsr    message
  692.     addq.w    #1,d4        adjust for partly inside a block
  693.     ext.l    d4
  694.     add.l    d4,a4
  695.     sub.l    #128,a4
  696.     bsr    waitfin
  697.     bra    xreclp0
  698.  
  699. * Missed checksum
  700. xrcheckm
  701.     lea.l    xchksm2(a5),a0
  702.     bsr    message
  703.  
  704. xrchecks
  705.     sub.l    #128,a4        backtrack some bytes
  706.     lea.l    xchksm(a5),a0
  707.     bsr    message
  708.     move.b    d3,d1        real checksum
  709.     bsr    hexbyte
  710.     lea.l    xchksm1(a5),a0
  711.     bsr    message
  712.     move.b    d0,d1
  713.     bsr    hexbyte
  714.     bsr    newline
  715.     bsr    waitfin
  716.     bra    xreclp0        and go back for more, with a Nak!
  717.  
  718. xrslowr    
  719.     bsr    waitfin        Does not need any backtracking of a4
  720.     lea.l    slowm1(a5),a0
  721.     bsr    message
  722.     bra    xreclp0
  723.  
  724. *-------------------------------------------------------------------------*
  725. xrbadblk
  726.     addq.b    #1,d1        check for previous block being repeated
  727.     cmp.b    d1,d2        are they the same now?
  728.     beq.s    xrbbb1
  729. xrbadbl2
  730.     bsr    waitfin        must have been a genuine bad block
  731.     lea.l    badblkm(a5),a0
  732.     bsr    message
  733.     bra    xreclp0
  734.  
  735. * If previous block was repeated, then do an ACK to get it up to date
  736. xrbbb1    
  737.     bsr    sendack        and go back for more
  738.     bra    xreclp1a    dont send NAK
  739.  
  740. *-------------------------------------------------------------------------*
  741. xreceot    
  742.     move.b    #ack,d1
  743.     bsr    sendser
  744.     move.l    a4,bufptr(a5)    reflect new buffer value
  745.  
  746.     lea.l    xrecm2(a5),a0
  747.     bsr    message
  748.  
  749.     bra    menuagn
  750.  
  751.  
  752. xrecm2    
  753.     dc.b    cr,lf,"File downloaded successfully.",cr,lf,lf,0
  754.     even
  755.  
  756. slowm1    
  757.     dc.b    cr,lf,"Slow (or not enough) response.",cr,lf,0
  758.     even
  759.  
  760. badblkm    
  761.     dc.b    cr,lf,"Bad block received.",cr,lf,0
  762.     even
  763.  
  764. misschm    
  765.     dc.b    cr,lf,"Missed character in block.",cr,lf,0
  766.     even
  767.  
  768. xchksm    
  769.     dc.b    cr,lf,"Checksum Error, should be $",0
  770.     even
  771.  
  772. xchksm1    
  773.     dc.b    ", was $",0
  774.     even
  775.  
  776. xchksm2    
  777.     dc.b    cr,lf,"Checksum missing.",cr,lf,0
  778.     even
  779.  
  780. *-------------------------------------------------------------------------*
  781. sendack    
  782.     move.b    #ack,d1
  783.     bra    sendser
  784.  
  785. waitfin    move.w    #2,d6        wait until entire block is sent
  786.     bsr    waitser
  787.     bpl.s    waitfin
  788.  
  789.     rts
  790.  
  791. *-------------------------------------------------------------------------*
  792. warnmess
  793.     lea.l    warnmes(a5),a0
  794.     bra    message
  795.  
  796. warnmes    
  797.     dc.b    cr,lf,lf,"To exit: hit a key, and be patient.",cr,lf,lf,0
  798.     even
  799.  
  800.  
  801. *-------------------------------------------------------------------------*
  802. * Print up a block...
  803. prblock    
  804.     movem.l    d0-a6,-(sp)
  805.     lea.l    pblokm(a5),a0
  806.     bsr    message
  807.     move.w    d2,d1
  808.     bsr    hexbyte
  809.     move.b    #cr,d1        do a carriage ret ONLY to keep on same line
  810.     bsr    wrchar
  811.     movem.l    (sp)+,d0-a6
  812.     rts
  813.  
  814. pblokm    
  815.     dc.b    "Current block $",0
  816.     even
  817.  
  818. *-------------------------------------------------------------------------*
  819. askfile    
  820.     lea.l    filemes(a5),a0    Point to message
  821.     bsr    message        print it
  822.     bsr    getline        gets a line of text, in our case a filename
  823.     clr.l    d0        Zero the counter
  824.     move.b    ibuff+1(a5),d0    How many characters typed?
  825.     beq    endfile        Exit now!
  826.  
  827.     lea.l    whatfile(a5),a0    Point to filename
  828.     lea.l    ibuff+2(a5),a1    Point to input buffer text
  829.     subq.w    #1,d0        decrement count ready for a dbra
  830. copyfn    
  831.     move.b    (a1)+,(a0)+    Copy input buffer to filename buffer
  832.     dbra    d0,copyfn    continue with loop
  833.  
  834.     clr.b    (a0)+        Set the terminator to NULL
  835.     moveq    #$ff,d0        Set TRUE flag
  836. endfile    
  837.     rts            And zzzap!
  838.  
  839. *-------------------------------------------------------------------------*
  840. loadfile
  841.     bsr    openrd        Open file for reading
  842.     tst.l    d0
  843.     bmi.s    exitlod        Did it open ok?
  844.  
  845.     bsr    rdfile        Read it
  846.     bra    closfile    Close it
  847.  
  848. exitlod    
  849.     lea.l    lodmes(a5),a0    point to error mess
  850.     bra    message
  851.  
  852.  
  853. lodmes    
  854.     dc.b    cr,lf,lf,"You sure it exists??",cr,lf
  855.     dc.b    "I`m having trouble locating it!",cr,lf,lf,0
  856.     even
  857.  
  858. *-------------------------------------------------------------------------*
  859. savefile
  860.     bsr    createit    Create file if necessary
  861.     tst.l    d0        If error, must already exist..
  862.     bpl.s    notexist
  863.  
  864.     bsr    openwrt        File xfer, the idjut way!
  865.     tst.l    d0        Did file open ok?
  866.     bmi.s    exitsav
  867. notexist
  868.     bsr    wrtfile        write the file
  869.     bra    closfile    Close it now!
  870.  
  871. exitsav    
  872.     lea.l    ferrmes(a5),a0    Show a file error
  873.     bra    message
  874.  
  875.  
  876. ferrmes    
  877.     dc.b    cr,lf,lf,"File Error, not saved!",cr,lf,lf,0
  878.     even
  879.  
  880. *-------------------------------------------------------------------------*
  881. createit
  882.     move.w    #0,-(sp)    zero attributes, for a normal file
  883.     pea    whatfile(a5)    address of filename
  884.     move.w    #$3c,-(sp)    code to create a file
  885.     trap    #1        GEMDOS Bios
  886.     move.w    d0,handle(a5)    Remember handle reference
  887.     addq.l    #8,sp        Correct stack
  888.     rts            Ignore errors, cos I dont give-a-damn!
  889.  
  890. *-------------------------------------------------------------------------*
  891. openrd    
  892.     move.w    #0,-(sp)    open for read
  893.     pea    whatfile(a5)    Address of filename
  894.     move.w    #$3d,-(sp)    code for open
  895.     trap    #1        GEMDOS Bios
  896.     move.w    d0,handle(a5)    File reference
  897.     addq.l    #8,sp        Correct stack
  898.     rts            Dun!
  899.  
  900. *-------------------------------------------------------------------------*
  901. openwrt    
  902.     move.w    #1,-(sp)    Means open for WRITE
  903.     pea    whatfile(a5)    Address of filename
  904.     move.w    #$3d,-(sp)    Code for `open`
  905.     trap    #1        GEMDOS Bios function
  906.     move.w    d0,handle(a5)    file reference returned
  907.     addq.l    #8,sp        Correct Stack
  908.     rts            Powee!
  909.  
  910. *-------------------------------------------------------------------------*
  911. rdfile    
  912.     pea    buffer(a5)    Address of where to put it!
  913.     move.l    #$7f00,-(sp)    Number of bytes (max) to read
  914.     move.w    handle(a5),-(sp) File reference
  915.     move.w    #$3f,-(sp)    Code for READ FILE
  916.     trap    #1        GEMDOS Bios
  917.     add.l    #12,sp        Correct stack
  918.     tst.l    d0        How many bytes?
  919.     bmi    exitrd        .. or file error
  920.  
  921.     add.l    d0,bufptr(a5)    update buffer size to new value
  922. exitrd    
  923.     rts
  924.  
  925. *-------------------------------------------------------------------------*
  926. wrtfile    
  927.     pea    buffer(a5)    Address of start of file
  928.     lea.l    buffer(a5),a1    Determine length
  929.     move.l    bufptr(a5),a0
  930.     sub.l    a1,a0        File`s length
  931.     move.l    a0,-(sp)    stack it
  932.     move.w    handle(a5),-(sp) File`s reference code
  933.     move.w    #$40,-(sp)    Code for Write File
  934.     trap    #1        GEMDOS Bios
  935.     add.l    #12,sp        Correct Stack
  936.     rts            Dunit, sire!
  937.  
  938. *-------------------------------------------------------------------------*
  939. closfile
  940.     move.w    handle(a5),-(sp) What file was dat?
  941.     move.w    #$3e,-(sp)    Code for CLOSE
  942.     trap    #1        GEMDOS Bios
  943.     addq.l    #4,sp        Correct Stack
  944.     rts            now what?
  945.  
  946. sbufmes    
  947.     dc.b    cr,lf,"Buffer Saved.",cr,lf,lf,0
  948.     even
  949.  
  950. *-------------------------------------------------------------------------*
  951. * Welcome message
  952. welcome    
  953.     dc.b    " ----------------------------------------",cr,lf
  954.     dc.b    " STerminal VT52 3.0,     By Jeremy E. San",cr,lf,lf
  955.     dc.b    " Freeware from Antic - the Atari Resource",cr,lf,lf
  956.     dc.b    " Copyright 1985 -- Argonaut Software Ltd.",cr,lf,lf
  957.     dc.b    " Press HELP for the Extended Menu.       ",cr,lf
  958.     dc.b    " ----------------------------------------",cr,lf,lf,0
  959.     even
  960.  
  961. * Exit current program and Return to GEM/desktop...
  962. exitprog
  963.     bsr    newline        Give a carriage Return
  964.     move.w    #0,-(sp)        code for `exit`
  965.     clr.l    d0        Not sure I need this in? but just in case!
  966.     trap    #1        GEMDOS Bios
  967.  
  968. * Shouldn`t ever get to here:
  969.     addq.l    #2,sp        Correct stack in case it ever gets here!
  970.     rts            Unnecessary, but -- just in case!
  971. *                Ya never know, with these ATARI...
  972. *                ...(hehehe) products!
  973.  
  974. *-------------------------------------------------------------------------*
  975. * Initialise various bits of memory etc ....
  976. * Entry: Nothing special
  977. * Exit: Sets up hardware registers, if needed, and other things.
  978. init    
  979.     move.w    #brate,d0        Default baudrate = 300
  980.     bsr    setbaud            Set it
  981.     lea.l    buffer(a5),a0        Default buffer pointer
  982.     move.l    a0,bufptr(a5)        ie: clear buffer
  983.  
  984.     move.w    #esc,d1            Set auto-wrap to occur
  985.     bsr    wrchar
  986.     move.w    #$76,d1            ...in Atari VT52 mode
  987.     bsr    wrchar
  988.     move.w    #esc,d1            clear the screen
  989.     bsr    wrchar
  990.     move.w    #"E",d1
  991.     bsr    wrchar            ... and return
  992.     bra    flushser            get rid of extraneous data
  993.  
  994. *-------------------------------------------------------------------------*
  995. * Wait for a character from the TOS console (keyboard)
  996. * Entry: Nothing special
  997. * Exit: Keyboard character in d0.b  Also possible register loss
  998. rdchar    
  999.     movem.l    d1-a6,-(sp)    Save all reggies
  1000.     move.w    #1,-(sp)        Get character from keyboard via BIOS
  1001.     trap    #1        GEMDOS Bios call
  1002.     addq.l    #2,sp        Correct Stack
  1003.     movem.l    (sp)+,d1-a6    Get Dem reggies
  1004.     rts            Yahooo!
  1005.  
  1006. *-------------------------------------------------------------------------*
  1007. * Prints up a message pointed to by a0.  Terminated by a 0.
  1008. * Entry: a0 = point to start of text.
  1009. * Exit: No register damage
  1010. message    
  1011.     movem.l    d1/a0,-(sp)        Save reggies
  1012.     clr.w    d1            Clear a word
  1013. messag2    
  1014.     move.b    (a0)+,d1        Get a character
  1015.     beq.s    mesfin            Terminator=0?
  1016.     
  1017.     bsr.s    wrchar            Display it
  1018.     bra.s    messag2            .. and loop back for more
  1019. mesfin    
  1020.     movem.l    (sp)+,d1/a0        Restore reggies
  1021.     rts                Zapow!
  1022.  
  1023. *-------------------------------------------------------------------------*
  1024. * Write a character in to console using TOS.
  1025. * Entry: d1 = character to display
  1026. * Exit: No register damage (methinks: movem overkill!?)
  1027. wrchar    
  1028.     movem.l    d0-d7/a0-a6,-(sp)    Save all known reggies
  1029.     move.w    d1,-(sp)        Stack character to be printed
  1030.     move.w    #2,-(sp)        Code for Write Character
  1031.     trap    #1            GEMDOS Bios
  1032.     addq.l    #4,sp            Correct the Stack
  1033.     movem.l    (sp)+,d0-d7/a0-a6    Restore Dem Dere Reggies
  1034.     rts                Wheee
  1035.  
  1036. *-------------------------------------------------------------------------*
  1037. scankey    
  1038.     move.w    #$0b,-(sp)        Is a key pending?
  1039.     trap    #1            GEMDOS Bios
  1040.     addq.l    #2,sp            Correct Stack
  1041.     tst.l    d0            Any key in buffer?
  1042.     bpl.s    skipkey            Nope, so quit while going`s good!
  1043. getkey    
  1044.     move.w    #$07,-(sp)        Get a key from buff without echo!
  1045.     trap    #1            GEMDOS Bios
  1046.     addq.l    #2,sp            Correct Stack
  1047.     rts                Return the key pressed
  1048.  
  1049. skipkey    
  1050.     moveq    #0,d0            Signal No key pressed
  1051.     rts                .. and exit.
  1052.  
  1053. *-------------------------------------------------------------------------*
  1054. * Enter with d6 = to number of seconds to wait...
  1055. waitser    
  1056.     subq.w    #1,d6
  1057. waitser1
  1058.     move.w    #10000,d7        wait for char for one second
  1059. waitser2
  1060.     bsr    scanser
  1061.     dbpl    d7,waitser2
  1062.     
  1063.     bpl.s    retwait1
  1064.     
  1065.     dbra    d6,waitser1
  1066. retwait1
  1067.     rts
  1068.  
  1069. *-------------------------------------------------------------------------*
  1070. * Scans for input from the serial port, returns with d0=0 if nothing!
  1071. scanser    
  1072.     move.w    #1,-(sp)        Code for serial port
  1073.     move.w    #1,-(sp)        Code for Pending?
  1074.     trap    #13        Is a char waiting in serial port?
  1075.     addq.l    #4,sp        Correct Stack
  1076.     tst.l    d0        Yes...?
  1077.     bpl.s    skipser        Nope, snif!
  1078.  
  1079.     move.w    #1,-(sp)        Serial port code
  1080.     move.w    #2,-(sp)        Code for Get character
  1081.     trap    #13        Extended Bios function
  1082.     addq.l    #4,sp        Correct Stack
  1083.     rts            Dun!
  1084.  
  1085. skipser    
  1086.     moveq    #-1,d0        Signal no character there
  1087.     rts            .. and go back again
  1088.  
  1089. *-------------------------------------------------------------------------*
  1090. * Sends character in d1 to serial port
  1091. sendser    
  1092.     move.w    d1,-(sp)        Stack character to be sent
  1093.     move.w    #4,-(sp)        Code for SEND SERIAL
  1094.     trap    #1        GEMDOS Bios call
  1095.     addq.l    #4,sp        Correct Stack
  1096.     rts            Dun!
  1097.  
  1098.  
  1099. *-------------------------------------------------------------------------*
  1100. * gets a line of text via BIOS
  1101. getline    
  1102.     pea    ibuff(a5)    Point to input buffer
  1103.     move.b    #32,ibuff(a5)    maximum of 32 characters
  1104.     move.w    #$0a,-(sp)    code for get a line
  1105.     trap    #1        GEMDOS BIOS
  1106.     addq.l    #6,sp        Correct stack
  1107.     rts
  1108.  
  1109. *-------------------------------------------------------------------------*
  1110. * Hex printout routines,
  1111. * Entry: Prints hex string of d1.w as hexascii digits.
  1112. * Exit: No register damage.
  1113. hexbyte    
  1114.     move.w    d1,-(sp)    Stack our byte
  1115.     bra.s    dobyte        Print up just a byte-long
  1116. hexlong    
  1117.     swap    d1        Get top word at bottom
  1118.     bsr    hexword        Print up top word
  1119.     swap    d1        Get low word again to fall into hexword
  1120. hexword    
  1121.     move.w    d1,-(sp)        Stack our Word
  1122.     lsr.w    #8,d1        Shift word 12 places to right
  1123.     lsr.w    #4,d1        . . .
  1124.     bsr.s    hexnibbl        Print a nybble
  1125.     move.w    (sp),d1        Get
  1126.     lsr.w    #8,d1         next
  1127.     bsr.s    hexnibbl              digit...
  1128. dobyte    
  1129.     move.w    (sp),d1        Print
  1130.     lsr.w    #4,d1         up
  1131.     bsr.s    hexnibbl              a
  1132.     move.w    (sp)+,d1               byte
  1133. hexnibbl    and.w    #15,d1        Mask useless contents
  1134.     cmp.b    #9,d1        Is it a non numeric digit?
  1135.     bls.s    hexnib2        Yes, so dont correct for ALpha
  1136.     
  1137.     add.b    #7,d1        Skip symbols in ASCII, to get alphas
  1138. hexnib2    
  1139.     add.b    #$30,d1        Convert to ASCII from numeric
  1140.     bra    wrchar        Prnit character
  1141.  
  1142.  
  1143. *-------------------------------------------------------------------------*
  1144. * Print a SPACE.  Corrupts d1
  1145. dospace    
  1146.     move.w    #32,d1        Dats a SSSSpace?
  1147.     bra    wrchar        Print it!
  1148.  
  1149. *-------------------------------------------------------------------------*
  1150. * Print a carriage return and a linefeed.  Corrupts d1
  1151. newline    
  1152.     move.w    #cr,d1        Carriage Return, folks
  1153.     bsr    wrchar        Print
  1154.     move.w    #lf,d1        Line Feed
  1155.     bra    wrchar        Print
  1156.  
  1157. *-------------------------------------------------------------------------*
  1158. * Sets the baud rate :
  1159. setbaud    
  1160.     move.w    #-1,-(sp)        scr
  1161.     move.w    #-1,-(sp)        tsr
  1162.     move.w    #-1,-(sp)        rsr
  1163.     move.w    #-1,-(sp)        ucr    
  1164.     move.w    #-1,-(sp)        flowctrl
  1165.     move.w    d0,-(sp)            baud rate
  1166.  
  1167.     move.w    #15,-(sp)        Code for rsconf
  1168.     trap    #14            Extended Atari function
  1169.     add.w    #14,sp            Correct Stack
  1170.  
  1171.     rts
  1172.  
  1173. *-------------------------------------------------------------------------*
  1174. * Storage locations and other misc variables...
  1175.  
  1176. whatfile
  1177.     dc.b    "SERIAL.TXT"
  1178.     even
  1179.     dc.l    0,0,0,0,0,0,0,0,0,0,0,0    < Buffer space!
  1180.  
  1181. *-------------------------------------------------------------------------*
  1182. * Long words
  1183.  
  1184. bufptr    
  1185.     dc.l    buffer    Pointer to current buffer position
  1186. ubufptr    
  1187.     dc.l    buffer    Uploading buffer pointer
  1188.  
  1189. *-------------------------------------------------------------------------*
  1190. * Words
  1191. handle    
  1192.     dc.w    0    Filename handle (reference code)
  1193.  
  1194. *-------------------------------------------------------------------------*
  1195. * Bytes
  1196. fileflag 
  1197.     dc.b    0    Uploading/Downloading flag?
  1198.     even
  1199.  
  1200.     bss
  1201.     even
  1202.  
  1203. *-------------------------------------------------------------------------*
  1204.     ds.l    256    256 stack entries
  1205. ustk    
  1206.     ds.l    1    ^ Local Stack area (goes backwards)
  1207. ibuff    
  1208.     ds.b    82    80 byte input buffer
  1209. buffer    
  1210.     ds.b    65536    64k`s worth of capture buffer
  1211.     even
  1212.  
  1213.     end
  1214. dddddddddddddddddddddddddddd